home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio-DSP / NU / Source / NuGraphicCell.m < prev    next >
Encoding:
Text File  |  1992-11-29  |  3.8 KB  |  110 lines

  1. #import "NuGraphicCell.h"
  2. #import <appkit/NXHelpPanel.h>
  3. #import <appkit/Application.h>
  4. #import <appkit/workspaceRequest.h>
  5. #import <appkit/NXBitmapImageRep.h>
  6. #import <appkit/View.h>
  7. #import <objc/List.h>
  8. #import <strings.h>
  9. #import "WorkspaceManager.h"
  10. #import <libc.h>
  11. #import <appkit/tiff.h>
  12. extern id Nu ; /* for debugging */
  13. @implementation NuGraphicCell: NXGraphicCell
  14. {
  15. }
  16.  
  17.  
  18. - (BOOL) trackMouse:(NXEvent *) theEvent inRect:(const NXRect *) cellFrame ofView:controlView ;
  19. { // inspired by some old code from Joe Freeman of NeXT inc's
  20.   // public domain multimedia objects
  21.   if(theEvent->data.mouse.click == 2) // if a double-click...
  22.   { id controlWindow ;
  23.     char *path, *fullPath ;
  24.     int fullPathLength ;
  25.     controlWindow = [controlView window] ;
  26.     // my filename is in the contents ivar...if we are
  27.     // in a helpPanel, message it to create a full pathname
  28.     if([controlWindow isMemberOf: [NXHelpPanel class]])
  29.     { // we are in a help panel...do the following contortions
  30.       // in order to get our full pathname
  31.       char *helpFile ;
  32.       path = (char *) [controlWindow helpDirectory] ;
  33.       helpFile = [controlWindow helpFile] ;
  34.       fullPathLength = strlen(path) + strlen(helpFile) + strlen(contents) ;
  35.       fullPath = (char *) alloca(fullPathLength + 3) ;
  36.       sprintf(fullPath,"%s/%s/%s",path,helpFile,contents) ;
  37.       [[Application workspace] openFile:fullPath] ;
  38.      }
  39.      else if([controlWindow isKindOf: [WorkspaceManager class]])
  40.      { // we are in a workspace (or one of its subclasses) window.
  41.        // Easier to get full path, but if workspace has not been
  42.        // saved, it is impossible.
  43.        path = [controlWindow fileName] ;
  44.        if(path[0] == '\0') // window not saved...can't open it
  45.        { NXRunAlertPanel("Nu",
  46.           "Can't do this operation from an untitled document",
  47.            NULL,NULL,NULL) ;
  48.          return NO ; 
  49.        }
  50.        fullPathLength = strlen(path) + strlen(contents) ;
  51.        fullPath = (char *) alloca(fullPathLength + 2) ;
  52.        sprintf(fullPath,"%s/%s",path,contents) ;
  53.        [[Application workspace] openFile:fullPath] ;
  54.      }
  55.      // else do nothing
  56.   }
  57.   return YES;
  58. }
  59.  
  60.  
  61. char * contentsOfStream(NXStream *aStream)
  62. { // push a null character (assures that if
  63.   // aStream contains text, it is a NULL terminated
  64.   // cstring) onto aStream, return a pointer to aStream's
  65.   // memorybuffer
  66.  int len, maxLen ;
  67.  char *buffer ;
  68.  NXPutc(aStream,'\0') ;
  69.  NXGetMemoryBuffer(aStream,&buffer,&len,&maxLen) ;
  70.  return buffer ;
  71. }   
  72.  
  73. - delayedSave: controlWin ;
  74. { // Write our image to a file, using controlWin
  75.   // to get the path, and contents to provice the
  76.   // the file name.
  77.   // First, check that our window understands fileName...
  78.   if([controlWin respondsTo: @selector(fileName)])
  79.   { NXStream *nameStream, *imageStream ;
  80.     nameStream = NXOpenMemory(NULL,0,NX_WRITEONLY);
  81.     NXPrintf(nameStream,"%s/%s",[controlWin fileName],contents) ;
  82.     imageStream = NXOpenMemory(NULL,0,NX_WRITEONLY);
  83.     [[support bestRepresentation]writeTIFF:imageStream  
  84.        usingCompression:NX_TIFF_COMPRESSION_LZW];
  85.   // [support writeTIFF:stream usingCompression:NX_TIFF_COMPRESSION_NONE];
  86.     NXSaveToFile(imageStream, contentsOfStream(nameStream)) ;
  87.     NXCloseMemory(nameStream, NX_FREEBUFFER);
  88.     NXCloseMemory(imageStream, NX_FREEBUFFER);
  89.   }
  90.   return self ;
  91. }
  92.  
  93.  
  94. - writeRichText:(NXStream *)stream forView:controlView ;
  95. { // redefine this method so that cells which have
  96.   // been created via NuText's pasteScreen: method
  97.   // save their image to disk
  98.   if(!strncmp(contents,NUSCREENPASTE,strlen(NUSCREENPASTE)))
  99.   { id controlWin ;
  100.     controlWin = [controlView window] ;
  101.     // can't actually save yet because the rtfd directory
  102.     // hasn't been created yet...schedule it for later...
  103.     [self perform:@selector(delayedSave:) 
  104.     with:controlWin  afterDelay:5 cancelPrevious:YES];
  105.   }
  106.  return [super writeRichText: stream forView: controlView] ;
  107. }
  108.  
  109. @end
  110.